import request from "@/utils/request";
import { useUserStore } from '@/stores/user';
const userStore = useUserStore();
const userId = userStore.userInfo.id;
const getToken = () => {
    const userStore = useUserStore();
    return userStore.token;
};

//创建订单接口
export const createOrder = (orderData) => {
  return request.post(`/order/create?userId=${userId}`, JSON.stringify(orderData), { // 直接传递 orderData
    headers: {
      'Authorization': getToken(), // 获取用户 token
      'Content-Type': 'application/json' // 确保服务器知道请求体格式
    }
  })
}
//多个商品订单接口
export const createMultiOrder = (orderData) => {
  return request.post(`/order/batch-create`, JSON.stringify(orderData), { // 直接传递 orderData
    headers: {
      'Authorization': getToken(), // 获取用户 token
      'Content-Type': 'application/json' // 确保服务器知道请求体格式
    }
  })
}


//获取订单列表接口
export const getOrderList = () => {
  return request.get('/order/list', {
    headers: {
      'Authorization': getToken()
    }
  })
}
//支付订单接口
export const payOrder = (orderNumber) => {
  return request.put(`/order/status/${orderNumber}`,{
    status: 'paid'
  },  {
    headers: {
      'Authorization': getToken()
    }
  })
}

//确认收货接口
export const confirmOrder = (orderNumber) => {
  return request.put(`/order/status/${orderNumber}`,{
    status: 'delivered'
  },  {
    headers: {
      'Authorization': getToken()
    }
  })
}

//删除订单接口
export const deleteOrder = (orderId) => {
  return request.delete(`/order/${orderId}`, {
    headers: {
      'Authorization': getToken()
    }
  })
}

